
<!DOCTYPE HTML>
<html lang="" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>权限控制 · GitBook</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.2">
        
        
        
    
    <link rel="stylesheet" href="gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="gitbook/gitbook-plugin-highlight/website.css">
                
            
                
                <link rel="stylesheet" href="gitbook/gitbook-plugin-search/search.css">
                
            
                
                <link rel="stylesheet" href="gitbook/gitbook-plugin-fontsettings/website.css">
                
            
        

    

    
        
    
        
    
        
    
        
    
        
    
        
    

        
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="gitbook/images/favicon.ico" type="image/x-icon">

    
    <link rel="next" href="keyboard.html" />
    
    
    <link rel="prev" href="systembartint.html" />
    

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="Type to search" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
    
    

    

    
        
        <li class="header">----安卓 UI----</li>
        
        
    
        <li class="chapter " data-level="1.1" data-path="./">
            
                <a href="./">
            
                    
                    Introduction
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2" data-path="view.html">
            
                <a href="view.html">
            
                    
                    自定义控件和measure
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3" data-path="canvas-paint.html">
            
                <a href="canvas-paint.html">
            
                    
                    draw和canvas，paint详解
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4" data-path="anim.html">
            
                <a href="anim.html">
            
                    
                    动画
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5" data-path="notify.html">
            
                <a href="notify.html">
            
                    
                    notify系列库
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6" data-path="loading.html">
            
                <a href="loading.html">
            
                    
                    loading系列库
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7" data-path="status-ui.html">
            
                <a href="status-ui.html">
            
                    
                    StatusUI系列库
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8" data-path="touch-scroll.html">
            
                <a href="touch-scroll.html">
            
                    
                    滑动
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9" data-path="layout.html">
            
                <a href="layout.html">
            
                    
                    Layout
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.10" data-path="textview.html">
            
                <a href="textview.html">
            
                    
                    TextView
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11" data-path="drawable.html">
            
                <a href="drawable.html">
            
                    
                    Drawable
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.12" data-path="item-template.html">
            
                <a href="item-template.html">
            
                    
                    列表Adapter模板化
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.13" data-path="recyclerview.html">
            
                <a href="recyclerview.html">
            
                    
                    RecyclerView全解
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.14" data-path="design.html">
            
                <a href="design.html">
            
                    
                    MeterialDesign详解
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.15" data-path="component.html">
            
                <a href="component.html">
            
                    
                    AyoComponent基础库--Activity和Fragment
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.16" data-path="systembartint.html">
            
                <a href="systembartint.html">
            
                    
                    SystembarTint
            
                </a>
            

            
        </li>
    
        <li class="chapter active" data-level="1.17" data-path="permission-ask.html">
            
                <a href="permission-ask.html">
            
                    
                    权限控制
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.18" data-path="keyboard.html">
            
                <a href="keyboard.html">
            
                    
                    小键盘
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.19" data-path="notification.html">
            
                <a href="notification.html">
            
                    
                    Notification
            
                </a>
            

            
        </li>
    

    
        
        <li class="header">----安卓 foundation----</li>
        
        
    
        <li class="chapter " data-level="2.1" data-path="mvp.html">
            
                <a href="mvp.html">
            
                    
                    MVP
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.2" data-path="rxjava.html">
            
                <a href="rxjava.html">
            
                    
                    RxJava
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.3" data-path="lang.html">
            
                <a href="lang.html">
            
                    
                    常用工具类
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.4" data-path="http.html">
            
                <a href="http.html">
            
                    
                    http
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.5" data-path="xml.html">
            
                <a href="xml.html">
            
                    
                    xml解析
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.6" data-path="json-reporter.html">
            
                <a href="json-reporter.html">
            
                    
                    Json解析
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.7" data-path="inject.html">
            
                <a href="inject.html">
            
                    
                    ButterKnife
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.8" data-path="thread.html">
            
                <a href="thread.html">
            
                    
                    安卓线程和looper
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.9" data-path="process.html">
            
                <a href="process.html">
            
                    
                    多进程
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.10" data-path="eventbus.html">
            
                <a href="eventbus.html">
            
                    
                    EventBus
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.11" data-path="db.html">
            
                <a href="db.html">
            
                    
                    数据库和ContentProvider
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.12" data-path="job.html">
            
                <a href="job.html">
            
                    
                    定时任务
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.13" data-path="service.html">
            
                <a href="service.html">
            
                    
                    service
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.14" data-path="opt-mem.html">
            
                <a href="opt-mem.html">
            
                    
                    内存优化
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.15" data-path="opt-network.html">
            
                <a href="opt-network.html">
            
                    
                    网络优化
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.16" data-path="opt-anr.html">
            
                <a href="opt-anr.html">
            
                    
                    anr排查
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.17" data-path="opt-ui.html">
            
                <a href="opt-ui.html">
            
                    
                    UI卡顿优化
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.18" data-path="opt-launch.html">
            
                <a href="opt-launch.html">
            
                    
                    启动优化
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.19" data-path="opt-launch.html">
            
                <a href="opt-launch.html">
            
                    
                    混淆
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.20" data-path="hotfix.html">
            
                <a href="hotfix.html">
            
                    
                    热补丁混淆
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.21" data-path="aar.html">
            
                <a href="aar.html">
            
                    
                    aar相关
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.22" data-path="route.html">
            
                <a href="route.html">
            
                    
                    Route路由
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.23" data-path="modules.html">
            
                <a href="modules.html">
            
                    
                    分模块，组件化，插件化
            
                </a>
            

            
        </li>
    

    
        
        <li class="header">----Gradle----</li>
        
        
    
        <li class="chapter " data-level="3.1" data-path="gradle.html">
            
                <a href="gradle.html">
            
                    
                    gradle基本配置
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.2" data-path="gradle-plugin.html">
            
                <a href="gradle-plugin.html">
            
                    
                    gradle插件开发
            
                </a>
            

            
        </li>
    

    
        
        <li class="header">----工具----</li>
        
        
    
        <li class="chapter " data-level="4.1" data-path="repos.html">
            
                <a href="repos.html">
            
                    
                    优秀博客，开源项目
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.2" data-path="packs.html">
            
                <a href="packs.html">
            
                    
                    自动打包，多渠道打包
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.3" data-path="gist.html">
            
                <a href="gist.html">
            
                    
                    代码片段和常见问题
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.4" data-path="stetho.html">
            
                <a href="stetho.html">
            
                    
                    stetho
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.5" data-path="fabric.html">
            
                <a href="fabric.html">
            
                    
                    fabric
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.6" data-path="app-update.html">
            
                <a href="app-update.html">
            
                    
                    自动升级
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.7" data-path="bugsnags.html">
            
                <a href="bugsnags.html">
            
                    
                    日志和崩溃统计
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.8" data-path="mail.html">
            
                <a href="mail.html">
            
                    
                    发邮件辅助接口
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.9" data-path="socail.html">
            
                <a href="socail.html">
            
                    
                    第三方登录和分享
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.10" data-path="pay-alipay.html">
            
                <a href="pay-alipay.html">
            
                    
                    支付宝支付
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.11" data-path="pay-wx.html">
            
                <a href="pay-wx.html">
            
                    
                    微信支付
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.12" data-path="umeng.html">
            
                <a href="umeng.html">
            
                    
                    友盟统计
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.13" data-path="push-jpush.html">
            
                <a href="push-jpush.html">
            
                    
                    推送-极光
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.14" data-path="push-xiaomi.html">
            
                <a href="push-xiaomi.html">
            
                    
                    推送-小米
            
                </a>
            

            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            Published with GitBook
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href="." >权限控制</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <h1 id="&#x6743;&#x9650;&#x63A7;&#x5236;">&#x6743;&#x9650;&#x63A7;&#x5236;</h1>
<p>github&#x5730;&#x5740;&#xFF1A;<a href="https://github.com/cowthan/AyoCompoment" target="_blank">https://github.com/cowthan/AyoCompoment</a></p>
<h2 id="21-&#x52A8;&#x6001;&#x6743;&#x9650;">2.1 &#x52A8;&#x6001;&#x6743;&#x9650;</h2>
<p>&#x6458;&#x81EA;&#xFF1A;<a href="http://www.jianshu.com/p/a51593817825" target="_blank">http://www.jianshu.com/p/a51593817825</a></p>
<p>&#x52A8;&#x6001;&#x6743;&#x9650;&#x7684;&#x95EE;&#x9898;&#x53EA;&#x5728;app&#x7684;targetSdk&#x548C;&#x624B;&#x673A;&#x7684;&#x7CFB;&#x7EDF;&#x7248;&#x672C;&#x90FD;&#x5927;&#x4E8E;&#x7B49;&#x4E8E;23&#x65F6;&#x751F;&#x6548;</p>
<ul>
<li>target=22&#x7684;apk&#x5728;6.0&#x4E0A;&#x4E0D;&#x7528;&#x7533;&#x8BF7;&#x6743;&#x9650;</li>
<li>target=23&#x7684;apk&#x5728;5.0&#x4E0A;&#x4E0D;&#x7528;&#x7533;&#x8BF7;&#x6743;&#x9650;</li>
<li>target=23&#x7684;apk&#x5728;6.0&#x4E0A;&#x9700;&#x8981;&#x7533;&#x8BF7;&#x6743;&#x9650;</li>
<li>&#x5982;&#x679C;&#x4F60;&#x8C03;&#x7528;&#x7684;&#x662F;&#x7B2C;&#x4E09;&#x65B9;&#x7684;&#x529F;&#x80FD;&#xFF0C;&#x5219;&#x4E0D;&#x9700;&#x8981;&#x7533;&#x8BF7;&#x6743;&#x9650;</li>
</ul>
<pre><code>&#x4EE5;&#x4E0B;&#x662F;&#x9700;&#x8981;&#x5355;&#x72EC;&#x7533;&#x8BF7;&#x7684;&#x6743;&#x9650;&#xFF0C;&#x5171;&#x5206;&#x4E3A;9&#x7EC4;&#xFF0C;&#x6BCF;&#x7EC4;&#x53EA;&#x8981;&#x6709;&#x4E00;&#x4E2A;&#x6743;&#x9650;&#x7533;&#x8BF7;&#x6210;&#x529F;&#x4E86;&#xFF0C;&#x5C31;&#x9ED8;&#x8BA4;&#x6574;&#x7EC4;&#x6743;&#x9650;&#x90FD;&#x53EF;&#x4EE5;&#x4F7F;&#x7528;&#x4E86;
- &#x9700;&#x8981;&#x73B0;&#x5728;manifest&#x91CC;&#x58F0;&#x660E;
- &#x4EE3;&#x7801;&#x91CC;&#x7528;&#x5230;&#x65F6;&#xFF0C;&#x603B;&#x662F;&#x9700;&#x8981;check&#xFF0C;&#x82E5;&#x6CA1;&#x6709;&#xFF0C;&#x5219;&#x5F39;&#x51FA;&#x5F39;&#x6846;&#x8BF7;&#x6C42;&#x7528;&#x6237;&#x7ED9;&#x6743;&#x9650;

  group:android.permission-group.CONTACTS
    permission:android.permission.WRITE_CONTACTS
    permission:android.permission.GET_ACCOUNTS
    permission:android.permission.READ_CONTACTS

  group:android.permission-group.PHONE
    permission:android.permission.READ_CALL_LOG
    permission:android.permission.READ_PHONE_STATE
    permission:android.permission.CALL_PHONE
    permission:android.permission.WRITE_CALL_LOG
    permission:android.permission.USE_SIP
    permission:android.permission.PROCESS_OUTGOING_CALLS
    permission:com.android.voicemail.permission.ADD_VOICEMAIL

  group:android.permission-group.CALENDAR
    permission:android.permission.READ_CALENDAR
    permission:android.permission.WRITE_CALENDAR

  group:android.permission-group.CAMERA
    permission:android.permission.CAMERA

  group:android.permission-group.SENSORS
    permission:android.permission.BODY_SENSORS

  group:android.permission-group.LOCATION
    permission:android.permission.ACCESS_FINE_LOCATION
    permission:android.permission.ACCESS_COARSE_LOCATION

  group:android.permission-group.STORAGE
    permission:android.permission.READ_EXTERNAL_STORAGE
    permission:android.permission.WRITE_EXTERNAL_STORAGE

  group:android.permission-group.MICROPHONE
    permission:android.permission.RECORD_AUDIO

  group:android.permission-group.SMS
    permission:android.permission.READ_SMS
    permission:android.permission.RECEIVE_WAP_PUSH
    permission:android.permission.RECEIVE_MMS
    permission:android.permission.RECEIVE_SMS
    permission:android.permission.SEND_SMS
    permission:android.permission.READ_CELL_BROADCASTS
</code></pre><pre><code>&#x4EE5;&#x4E0B;&#x662F;&#x666E;&#x901A;&#x6743;&#x9650;&#xFF0C;&#x76F4;&#x63A5;&#x5728;manifest&#x91CC;&#x7533;&#x8BF7;

android.permission.ACCESS_LOCATION_EXTRA_COMMANDS
  android.permission.ACCESS_NETWORK_STATE
  android.permission.ACCESS_NOTIFICATION_POLICY
  android.permission.ACCESS_WIFI_STATE
  android.permission.ACCESS_WIMAX_STATE
  android.permission.BLUETOOTH
  android.permission.BLUETOOTH_ADMIN
  android.permission.BROADCAST_STICKY
  android.permission.CHANGE_NETWORK_STATE
  android.permission.CHANGE_WIFI_MULTICAST_STATE
  android.permission.CHANGE_WIFI_STATE
  android.permission.CHANGE_WIMAX_STATE
  android.permission.DISABLE_KEYGUARD
  android.permission.EXPAND_STATUS_BAR
  android.permission.FLASHLIGHT
  android.permission.GET_ACCOUNTS
  android.permission.GET_PACKAGE_SIZE
  android.permission.INTERNET
  android.permission.KILL_BACKGROUND_PROCESSES
  android.permission.MODIFY_AUDIO_SETTINGS
  android.permission.NFC
  android.permission.READ_SYNC_SETTINGS
  android.permission.READ_SYNC_STATS
  android.permission.RECEIVE_BOOT_COMPLETED
  android.permission.REORDER_TASKS
  android.permission.REQUEST_INSTALL_PACKAGES
  android.permission.SET_TIME_ZONE
  android.permission.SET_WALLPAPER
  android.permission.SET_WALLPAPER_HINTS
  android.permission.SUBSCRIBED_FEEDS_READ
  android.permission.TRANSMIT_IR
  android.permission.USE_FINGERPRINT
  android.permission.VIBRATE
  android.permission.WAKE_LOCK
  android.permission.WRITE_SYNC_SETTINGS
  com.android.alarm.permission.SET_ALARM
  com.android.launcher.permission.INSTALL_SHORTCUT
  com.android.launcher.permission.UNINSTALL_SHORTCUT
</code></pre><p>&#x600E;&#x4E48;&#x7533;&#x8BF7;</p>
<p>&#x5148;&#x770B;manifest&#x91CC;&#xFF1A;</p>
<pre><code>&lt;!-- uses-permission-sdk-m&#x6807;&#x793A;&#x7684;&#x6743;&#x9650;&#x53EA;&#x5728;6.0&#x53CA;&#x5176;&#x4EE5;&#x4E0A;&#x7684;&#x673A;&#x5668;&#x4E0A;&#x88AB;&#x7533;&#x8BF7;&#xFF0C;&#x5728;&#x4F4E;&#x4E8E;6.0&#x7684;&#x8BBE;&#x5907;&#x91CC;&#x4E0D;&#x4F1A;&#x7533;&#x8BF7;&#xFF0C;&#x4E5F;&#x4E0D;&#x4F1A;&#x751F;&#x6548; --&gt;
&#x81EA;&#x52A8;&#x751F;&#x6548;&#xFF0C;&#x4E0D;&#x9700;&#x8981;&#x518D;&#x600E;&#x4E48;&#x7533;&#x8BF7;&#x4E86;
&lt;uses-permission-sdk-23 android:name=&quot;android.permission.READ_CONTACTS&quot; /&gt;
&lt;uses-permission-sdk-23 android:name=&quot;android.permission.WRITE_CONTACTS&quot; /&gt;

&lt;!-- &#x666E;&#x901A;&#x6743;&#x9650;&#x7533;&#x8BF7;&#xFF0C;&#x654F;&#x611F;&#x7684;&#x5FC5;&#x987B;&#x5728;&#x8FD0;&#x884C;&#x65F6;&#x52A8;&#x6001;&#x7533;&#x8BF7; --&gt;
&lt;uses-permission android:name=&quot;android.permission.CAMERA&quot;/&gt;
</code></pre><p>&#x4EE3;&#x7801;&#x91CC;&#x5224;&#x65AD;&#x6743;&#x9650;&#xFF1A;</p>
<pre><code>///----&#x5E72;&#x6D3B;&#x4E4B;&#x524D;&#x5224;&#x65AD;&#x662F;&#x5426;&#x6709;&#x6743;&#x9650;
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED) {
    // Camera permission has not been granted.
    requestCameraPermission();
} else {
    // Camera permissions is already available, show the camera preview.
    Log.i(TAG,&quot;CAMERA permission has already been granted. Displaying camera preview.&quot;);
    showCameraPreview();
}


///----&#x8BF7;&#x6C42;&#x7528;&#x6237;&#x6388;&#x6743;&#xFF0C;&#x5E76;&#x5224;&#x65AD;&#x662F;&#x7B2C;&#x4E00;&#x6B21;&#x8BF7;&#x6C42;&#xFF0C;&#x8FD8;&#x662F;&#x5DF2;&#x7ECF;&#x88AB;&#x62D2;&#x7EDD;&#x8FC7;&#xFF0C;&#x6216;&#x7528;&#x6237;&#x4E3B;&#x52A8;&#x53D6;&#x6D88;&#x8FC7;
/**
 * Requests the Camera permission.
 * If the permission has been denied previously, a SnackBar will prompt the user to grant the
 * permission, otherwise it is requested directly.
 */
private void requestCameraPermission() {
    Log.i(TAG, &quot;CAMERA permission has NOT been granted. Requesting permission.&quot;);

    // BEGIN_INCLUDE(camera_permission_request)
    if (ActivityCompat.shouldShowRequestPermissionRationale(this, Manifest.permission.CAMERA)) {
        // Provide an additional rationale to the user if the permission was not granted
        // and the user would benefit from additional context for the use of the permission.
        // For example if the user has previously denied the permission.
        Log.i(TAG, &quot;Displaying camera permission rationale to provide additional context.&quot;);

        ///&#x8FD9;&#x4E00;&#x5C42;&#x662F;&#x4E00;&#x4E2A;&#x7528;&#x6237;&#x53CB;&#x597D;&#x7684;&#x505A;&#x6CD5;&#xFF0C;&#x65E2;&#x7136;&#x7528;&#x6237;&#x4E3B;&#x52A8;&#x62D2;&#x7EDD;&#x8FC7;&#x6216;&#x8005;&#x53D6;&#x6D88;&#x8FC7;&#x8BE5;&#x6743;&#x9650;&#xFF0C;&#x90A3;&#x5C31;&#x5E94;&#x8BE5;&#x5728;&#x518D;&#x6B21;&#x7533;&#x8BF7;&#x65F6;&#x591A;&#x8BF4;&#x70B9;&#x4EC0;&#x4E48;
        Snackbar.make(mLayout, &quot;&#x4E4B;&#x524D;&#x7533;&#x8BF7;&#x8FC7;&#x88AB;&#x62D2;&#xFF0C;&#x6216;&#x8005;&#x7528;&#x6237;&#x53BB;&#x8BBE;&#x7F6E;&#x91CC;&#x5173;&#x95ED;&#x4E86;&#x8BE5;&#x6743;&#x9650;&#xFF0C;&#x5728;&#x8FD9;&#x91CC;&#x63D0;&#x793A;&quot;,
                Snackbar.LENGTH_INDEFINITE)
                .setAction(R.string.ok, new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        ActivityCompat.requestPermissions(PermissionMainActivity.this,
                                new String[]{Manifest.permission.CAMERA},
                                REQUEST_CAMERA);
                    }
                })
                .show();
    } else {
        // Camera permission has not been granted yet. Request it directly.
        ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.CAMERA}, REQUEST_CAMERA);
    }
    // END_INCLUDE(camera_permission_request)
}


///----&#x83B7;&#x5F97;&#x7528;&#x6237;&#x6388;&#x6743;&#x7ED3;&#x679C;
/**
 * Callback received when a permissions request has been completed.
 */
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions,
        @NonNull int[] grantResults) {

    if (requestCode == REQUEST_CAMERA) {
        // BEGIN_INCLUDE(permission_result)
        // Received permission result for camera permission.
        Log.i(TAG, &quot;Received response for Camera permission request.&quot;);

        // Check if the only required permission has been granted
        if (grantResults.length == 1 &amp;&amp; grantResults[0] == PackageManager.PERMISSION_GRANTED) {
            // Camera permission has been granted, preview can be displayed
            Log.i(TAG, &quot;CAMERA permission has now been granted. Showing preview.&quot;);
            Snackbar.make(mLayout, R.string.permision_available_camera,
                    Snackbar.LENGTH_SHORT).show();
        } else {
            Log.i(TAG, &quot;CAMERA permission was NOT granted.&quot;);
            Snackbar.make(mLayout, R.string.permissions_not_granted,
                    Snackbar.LENGTH_SHORT).show();

        }
        // END_INCLUDE(permission_result)

    } else if (requestCode == REQUEST_CONTACTS) {
        Log.i(TAG, &quot;Received response for contact permissions request.&quot;);

        // We have requested multiple permissions for contacts, so all of them need to be
        // checked.
        if (PermissionUtil.verifyPermissions(grantResults)) {
            // All required permissions have been granted, display contacts fragment.
            Snackbar.make(mLayout, R.string.permision_available_contacts,
                    Snackbar.LENGTH_SHORT)
                    .show();
        } else {
            Log.i(TAG, &quot;Contacts permissions were NOT granted.&quot;);
            Snackbar.make(mLayout, R.string.permissions_not_granted,
                    Snackbar.LENGTH_SHORT)
                    .show();
        }

    } else {
        super.onRequestPermissionsResult(requestCode, permissions, grantResults);
    }
}
</code></pre><p>&#x6CE8;&#x610F;&#xFF1A;</p>
<ul>
<li>requestPermission&#x4E00;&#x822C;&#x662F;&#x4E2A;&#x7CFB;&#x7EDF;&#x5BF9;&#x8BDD;&#x6846;</li>
<li>&#x4F46;&#x7B2C;&#x4E8C;&#x6B21;&#x5F39;&#x51FA;&#xFF0C;&#x53EF;&#x80FD;&#x4F1A;&#x5E26;&#x4E2A;&#x63D0;&#x793A;&#xFF1A;&#x4EE5;&#x540E;&#x4E0D;&#x518D;&#x5F39;&#x51FA;&#xFF0C;&#x5982;&#x679C;&#x7528;&#x6237;&#x9009;&#x4E86;&#xFF0C;&#x90A3;shouldShowRequestPermissionRationale&#x4F1A;&#x8FD4;&#x56DE;true<ul>
<li>&#x8868;&#x793A;&#x4F60;&#x9700;&#x8981;&#x7ED9;&#x7528;&#x6237;&#x4E00;&#x4E2A;&#x89E3;&#x91CA;</li>
<li>&#x4F46;&#x5B9A;&#x5236;&#x7CFB;&#x7EDF;&#x91CC;&#xFF0C;&#x8FD9;&#x4E2A;&#x53EF;&#x80FD;&#x603B;&#x662F;&#x8FD4;&#x56DE;false&#xFF0C;&#x5982;&#x5C0F;&#x7C73;&#x67D0;&#x7248;&#x672C;&#xFF0C;&#x4F1A;&#x5BFC;&#x81F4;&#x7528;&#x6237;&#x9009;&#x62E9;&#x4E0D;&#x518D;&#x5F39;&#x51FA;&#xFF0C;&#x5BF9;&#x8BDD;&#x6846;&#x771F;&#x5C31;&#x4E0D;&#x518D;&#x5F39;&#x51FA;&#x4E86;<ul>
<li>&#x4F60;request&#xFF0C;&#x4F46;&#x5BF9;&#x8BDD;&#x6846;&#x4E0D;&#x5F39;&#x51FA;&#xFF0C;&#x610F;&#x601D;&#x5C31;&#x662F;&#x76F4;&#x63A5;&#x56DE;&#x8C03;&#x6388;&#x6743;&#x5931;&#x8D25;</li>
<li>&#x89E3;&#x51B3;&#x65B9;&#x6848;&#x662F;&#x5728;onRequestPermissionResult&#x91CC;&#xFF0C;&#x7ED3;&#x679C;&#x4E0D;&#x4E3A;PackageManager.PERMISSION_GRANTED&#x65F6;&#xFF0C;&#x5F39;&#x51FA;&#x5E94;&#x7528;&#x4FE1;&#x606F;&#x754C;&#x9762;&#xFF0C;&#x8BA9;&#x7528;&#x6237;&#x8BBE;&#x7F6E;</li>
</ul>
</li>
</ul>
</li>
</ul>
<p>&#x4E0A;&#x9762;&#x8FD8;&#x6709;&#x9057;&#x6F0F;&#xFF0C;&#x5C31;&#x662F;&#x540C;&#x65F6;&#x7533;&#x8BF7;&#x591A;&#x4E2A;permission&#x65F6;&#xFF0C;&#x5F39;&#x51FA;&#x6846;&#x7684;&#x6837;&#x5B50;&#xFF0C;onResult&#x91CC;&#x7684;&#x56DE;&#x8C03;&#xFF0C;&#x7528;&#x5230;&#x65F6;&#x518D;&#x7814;&#x7A76;&#x5427;&#xFF0C;&#x77E5;&#x9053;&#x4E86;&#x5957;&#x8DEF;&#x5C31;&#x7B80;&#x5355;&#x4E86;</p>
<p>&#x4E0A;&#x9762;&#x7684;&#x4EE3;&#x5F88;&#x660E;&#x663E;&#x5F88;&#x7E41;&#x7410;&#xFF0C;&#x6240;&#x4EE5;&#x6211;&#x4EEC;&#x53EF;&#x4EE5;&#x5C01;&#x88C5;&#x4E00;&#x4E0B;</p>

                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                <a href="systembartint.html" class="navigation navigation-prev " aria-label="Previous page: SystembarTint">
                    <i class="fa fa-angle-left"></i>
                </a>
                
                
                <a href="keyboard.html" class="navigation navigation-next " aria-label="Next page: 小键盘">
                    <i class="fa fa-angle-right"></i>
                </a>
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"权限控制","level":"1.17","depth":1,"next":{"title":"小键盘","level":"1.18","depth":1,"path":"keyboard.md","ref":"keyboard.md","articles":[]},"previous":{"title":"SystembarTint","level":"1.16","depth":1,"path":"systembartint.md","ref":"systembartint.md","articles":[]},"dir":"ltr"},"config":{"gitbook":"*","theme":"default","variables":{},"plugins":[],"pluginsConfig":{"highlight":{},"search":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"fontsettings":{"theme":"white","family":"sans","size":2},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"}},"file":{"path":"permission-ask.md","mtime":"2017-04-09T14:37:42.248Z","type":"markdown"},"gitbook":{"version":"3.2.2","time":"2017-04-09T17:03:25.521Z"},"basePath":".","book":{"language":""}});
        });
    </script>
</div>

        
    <script src="gitbook/gitbook.js"></script>
    <script src="gitbook/theme.js"></script>
    
        
        <script src="gitbook/gitbook-plugin-search/search-engine.js"></script>
        
    
        
        <script src="gitbook/gitbook-plugin-search/search.js"></script>
        
    
        
        <script src="gitbook/gitbook-plugin-lunr/lunr.min.js"></script>
        
    
        
        <script src="gitbook/gitbook-plugin-lunr/search-lunr.js"></script>
        
    
        
        <script src="gitbook/gitbook-plugin-sharing/buttons.js"></script>
        
    
        
        <script src="gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    

    </body>
</html>

